//
//  MineViewController.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/7/25.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "MineViewController.h"

#import "SetViewController.h"

#import "PublishListViewController.h"
#import "FunViewController.h"
#import "RankListViewController.h"
#import "WealthViewController.h"
#import "LikeListViewController.h"
#import "CommentViewController.h"
#import "ConcernViewController.h"
#import "ShareViewController.h"

#import "WishListViewController.h"
#import "BuyListViewController.h"
#import "AddressManageViewController.h"
#import "InviteViewController.h"

#import "MineHeadTableViewCell.h"
#import "MineClassTableViewCell.h"

@interface MineViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) BaseTableView *tableView;

@property (nonatomic, strong) NSDictionary *personDict;

@end

@implementation MineViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleLightContent;
    self.navigationController.navigationBarHidden = YES;
    [self getData];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarStyle=UIStatusBarStyleDefault;
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.personDict = [NSDictionary dictionary];
    
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, -STATUS_BAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT + STATUS_BAR_HEIGHT)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, STATUS_BAR_HEIGHT + ScreenX375(10), ScreenX375(44), ScreenX375(44))];
    [backBtn setImage:ImageWithName(@"返回2") forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
}

- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)getData {
    NSDictionary *parameter = @{@"id":kNSUDefaultReadKey(@"userId"),@"userId":kNSUDefaultReadKey(@"userId")};
    [HttpManager postHttpRequestByGet:[NSString stringWithFormat:@"%@api/getUserInfo",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([status isEqualToString:@"200"]) {
            self.personDict = successResponse[@"data"];
            [self.tableView reloadData];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

#pragma mark - UITableViewDelegate,DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        MineHeadTableViewCell *cell = [MineHeadTableViewCell cellWithTableView:tableView andIndexPath:indexPath];
        if (self.personDict.allKeys.count > 0) {
            cell.dictionary = self.personDict;
        }
        cell.indexClick = ^(NSInteger index) {
            if (index == 0) {
                PublishListViewController *vc = [[PublishListViewController alloc] init];
                vc.num = [NSString stringWithFormat:@"%@",self.personDict[@"proNum"]];
                [self.navigationController pushViewController:vc animated:YES];
            }else if (index == 1) {
                FunViewController *vc = [[FunViewController alloc] init];
                vc.num = [NSString stringWithFormat:@"%@",self.personDict[@"fensNum"]];
                [self.navigationController pushViewController:vc animated:YES];
            }else if (index == 2) {
                RankListViewController *vc = [[RankListViewController alloc] init];
                vc.no = [NSString stringWithFormat:@"%@",self.personDict[@"no"]];
                [self.navigationController pushViewController:vc animated:YES];
            }else if (index == 3) {
                WealthViewController *vc = [[WealthViewController alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
            }else if (index == 4) {
                LikeListViewController *vc = [[LikeListViewController alloc] init];
                vc.num = [NSString stringWithFormat:@"%@",self.personDict[@"likeNum"]];
                [self.navigationController pushViewController:vc animated:YES];
            }else if (index == 5) {
                CommentViewController *vc = [[CommentViewController alloc] init];
                vc.num = [NSString stringWithFormat:@"%@",self.personDict[@"appraiseNum"]];
                [self.navigationController pushViewController:vc animated:YES];
            }else if (index == 6) {
                ConcernViewController *vc = [[ConcernViewController alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
            }else if (index == 7) {
                ShareViewController *vc = [[ShareViewController alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
            }
        };
        return cell;
    }else if (indexPath.section == 1) {
        MineClassTableViewCell *cell = [MineClassTableViewCell cellWithTableView:tableView andIndexPath:indexPath];
        cell.indexClick = ^(NSInteger index) {
            if (index == 0) {
                WishListViewController *vc = [[WishListViewController alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
            }else if (index == 1) {
                BuyListViewController *vc = [[BuyListViewController alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
            }else if (index == 2) {
                AddressManageViewController *vc = [[AddressManageViewController alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
            }else if (index == 3) {
                
            }else if (index == 4) {
                InviteViewController *vc = [[InviteViewController alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
            }else {
                SetViewController *vc = [[SetViewController alloc] init];
                vc.dict = self.personDict;
                [self.navigationController pushViewController:vc animated:YES];
            }
        };
        return cell;
    }
    UITableViewCell *cell = [[UITableViewCell alloc] init];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return ScreenX375(367) + STATUS_BAR_HEIGHT;
    }else {
        return ScreenX375(240);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
